package li.webqq.api;

import li.http.Response;

import org.apache.log4j.Logger;

/**
 * @author 明伟
 */
public class Login2Response extends Response {
    private static final Logger logger = Logger.getLogger(Login2Response.class);

    private String psessionid;
    private String vfwebqq;

    public String getPsessionid() {
        if (null == this.psessionid) {
            String body = super.getBody();
            logger.info("获取 psessionid body=" + body);
            int psessionidStart = body.indexOf("psessionid") + 13;
            if (psessionidStart < 13) {
                throw new RuntimeException("login faild response is " + body);
            }
            int psessionidEnd = body.indexOf(",", psessionidStart) - 1;
            this.psessionid = body.substring(psessionidStart, psessionidEnd);
        }
        return this.psessionid;
    }

    public String getVfwebqq() {
        if (null == this.vfwebqq) {
            String body = super.getBody();
            int psessionidStart = body.indexOf("vfwebqq") + 13;
            int psessionidEnd = body.indexOf(",", psessionidStart) - 1;
            this.vfwebqq = body.substring(psessionidStart, psessionidEnd);
        }
        return this.vfwebqq;
    }
}